package com.ag.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbContactLog;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbContactLog entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.ag.bean.TbContactLog
 * @author MyEclipse Persistence Tools
 */

public class TbContactLogDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbContactLogDAO.class);
	// property constants
	public static final String CT_AUDIO_URL = "ctAudioUrl";
	public static final String CT_SMS_CONTENT = "ctSmsContent";
	public static final String CT_FAX_FILE = "ctFaxFile";
	public static final String CT_CALLER = "ctCaller";
	public static final String CT_CALLED = "ctCalled";
	public static final String A = "a";
	public static final String B = "b";
	public static final String C = "c";

	protected void initDao() {
		// do nothing
	}

	public void save(TbContactLog transientInstance) {
		log.debug("saving TbContactLog instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbContactLog persistentInstance) {
		log.debug("deleting TbContactLog instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbContactLog findById(java.lang.String id) {
		log.debug("getting TbContactLog instance with id: " + id);
		try {
			TbContactLog instance = (TbContactLog) getHibernateTemplate().get(
					"com.ag.bean.TbContactLog", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbContactLog> findByExample(TbContactLog instance) {
		log.debug("finding TbContactLog instance by example");
		try {
			List<TbContactLog> results = (List<TbContactLog>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbContactLog instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TbContactLog as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbContactLog> findByCtAudioUrl(Object ctAudioUrl) {
		return findByProperty(CT_AUDIO_URL, ctAudioUrl);
	}

	public List<TbContactLog> findByCtSmsContent(Object ctSmsContent) {
		return findByProperty(CT_SMS_CONTENT, ctSmsContent);
	}

	public List<TbContactLog> findByCtFaxFile(Object ctFaxFile) {
		return findByProperty(CT_FAX_FILE, ctFaxFile);
	}

	public List<TbContactLog> findByCtCaller(Object ctCaller) {
		return findByProperty(CT_CALLER, ctCaller);
	}

	public List<TbContactLog> findByCtCalled(Object ctCalled) {
		return findByProperty(CT_CALLED, ctCalled);
	}

	public List<TbContactLog> findByA(Object a) {
		return findByProperty(A, a);
	}

	public List<TbContactLog> findByB(Object b) {
		return findByProperty(B, b);
	}

	public List<TbContactLog> findByC(Object c) {
		return findByProperty(C, c);
	}

	public List findAll() {
		log.debug("finding all TbContactLog instances");
		try {
			String queryString = "from TbContactLog";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbContactLog merge(TbContactLog detachedInstance) {
		log.debug("merging TbContactLog instance");
		try {
			TbContactLog result = (TbContactLog) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbContactLog instance) {
		log.debug("attaching dirty TbContactLog instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbContactLog instance) {
		log.debug("attaching clean TbContactLog instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbContactLogDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (TbContactLogDAO) ctx.getBean("TbContactLogDAO");
	}
}